package com.twu.biblioteca;

import java.util.List;
import java.util.Map;

/**
 * Created by sravanns on 19/06/14.
 */
public class ListCheckedOutBooks implements MenuAction {
    private Library library;
    private UserInterface userInterface;


    public ListCheckedOutBooks(Library library, UIApplication uiApplication) {
        this.library=library;
        this.userInterface=uiApplication;
    }



    @Override
    public Result performAction(String user) throws InterruptedException {
        Result result=new Result();
        Map<String,List<Book>> checkedList= library.getCheckedOutBooks();
        if(checkedList.size()==0)
        {
            result.setResult("no books checked out",false);
            return result;
        }
        for(String person: checkedList.keySet())
        {
            userInterface.display("*******\nUser  "+person+"\n Books checked out:");
            userInterface.displayBooks(checkedList.get(person));
            userInterface.display("\n*******");
        }
        result.setResult("listed "+checkedList.size(),true);
        return result;
    }
    @Override
    public String toString() {
        return "List checked out books";
    }
}
